function audioSignal = plucked_string(frequency , duration , ksData, Fs)
%ksData:       
%       sustain: de 0 a 1
%       randomness : 'gaussian', 'uniform'
%       volume: de 0 a 1
%       instrument: 'acoustic_guitar', 'banjo',
%       pickPosition: 0 a 1
%       pickDirection: 0 a 0.999


    x = zeros(round(Fs*duration), 1);
    delay = round(Fs/frequency);
    
    zi=randn(delay,1)*2-1;
    x=[zi;x(1:end-length(zi))];
    
    x=filter([1-ksData.pickDirection],[1 ksData.pickDirection],x);
    x=filter([1 zeros(1,round(ksData.pickPosition*delay))],[1],x);
    
    y=x;
    for k=delay+2:length(x)
        y(k) = x(k)+ (y(k-delay)+y(k-delay-1))/2;
    end
    note=y;
    note = note-mean(note);
    
    for k=1:length(note)
        note(k)=note(k)*exp(-(1-ksData.sustain)*5*k/Fs);
    end
    audioSignal=note;

    
    if ~strcmp(ksData.instrument,'none')
        [instrument Finstrument] = wavread(ksData.instrument);
        instrument=instrument/max(instrument);
        audioSignal=conv(audioSignal,instrument);
    end
    audioSignal=audioSignal/max(abs(audioSignal));
    audioSignal=audioSignal';
end

%     F = linspace(1/Fs, 1000, 2^12);
%     b  = firls(42, [0 1/delay 2/delay 1], [0 0 1 1]);
%     a  = [1 zeros(1, delay) -0.5 -0.5];
%     [H,W] = freqz(b, a, F, Fs);%para graficar
%     
%     if strcmp(ksData.randomness,'gaussian')
%         zi = randn(max(length(b),length(a))-1,1);
%     else
%         zi = rand(max(length(b),length(a))-1,1);
%     end
%     
%     note = filter(b, a, x, zi);